﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class BillDAO:IData<Bill> 
 	{
		public BillDAO(String myconnecString) : base(myconnecString) { }

		public override int OnSubmit(Bill item, int t) {
			 return connec.ExecuteNonQuery("sp_Bill", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + Bill.c_id, item.id), new SqlParameter("@" + Bill.c_customersId, item.customersId),
				 new SqlParameter("@" + Bill.c_address, item.address), new SqlParameter("@" + Bill.c_create_on, item.create_on),
				 new SqlParameter("@" + Bill.c_cardId, item.cardId), new SqlParameter("@" + Bill.c_total, item.total),
				 new SqlParameter("@" + Bill.c_discount, item.discount), new SqlParameter("@" + Bill.c_payment, item.payment),
				 new SqlParameter("@" + Bill.c_arrears, item.arrears), new SqlParameter("@" + Bill.c_credit, item.credit),
				 new SqlParameter("@" + Bill.c_status, item.status), new SqlParameter("@" + Bill.c_orderId, item.orderId),
				 new SqlParameter("@" + Bill.c_isActive, item.isActive)); 
		}

		public override Bill GetItem(IDataReader dr)
		{
			Bill obj = new Bill();
			obj.id = Convert.ToInt64(dr[Bill.c_id]);
			obj.customersId = Convert.ToInt64(dr[Bill.c_customersId]);
			obj.address = Convert.ToString(dr[Bill.c_address]);
			obj.create_on = Convert.ToDateTime(dr[Bill.c_create_on]);
			obj.cardId = Convert.ToInt64(dr[Bill.c_cardId]);
			obj.total = Convert.ToDecimal(dr[Bill.c_total]);
			obj.discount = Convert.ToDecimal(dr[Bill.c_discount]);
			obj.payment = Convert.ToDecimal(dr[Bill.c_payment]);
			obj.arrears = Convert.ToDecimal(dr[Bill.c_arrears]);
			obj.credit = Convert.ToString(dr[Bill.c_credit]);
			obj.status = Convert.ToInt32(dr[Bill.c_status]);
			obj.orderId = Convert.ToInt32(dr[Bill.c_orderId]);
			obj.isActive = Convert.ToInt32(dr[Bill.c_isActive]);
			return obj;
		}

		public override List<Bill> GetAll()
		{
			return GetAll("select * from " + Bill.b_Bill, CommandType.Text);
		}

		public override Bill GetItemById(object id)
		{
			throw new NotImplementedException();
		}

	}

 }
